package kiwi.assist.dev.guieditor.command {
	import ghostcat.skin.cursor.CursorHVDrag;
	import ghostcat.util.display.BitmapUtil;

	import kiwi.assist.dev.guieditor.event.GUIEditorEvent;
	import kiwi.assist.dev.guieditor.model.UiDetailVO;
	import kiwi.debug.Log;
	import kiwi.util.time.Time;

	import org.robotlegs.mvcs.Command;

	import flash.display.BitmapData;
	import flash.ui.Mouse;
	import flash.ui.MouseCursorData;
	import flash.utils.setInterval;

	/**
	 * 开始
	 * @author zhangming.luo
	 */
	public class GuiEditorStartupCommand extends Command {
		[Inject]
		public var detail : UiDetailVO;

		override public function execute() : void {
			super.execute();
			Log.registerAlertAppender(new ASWingMessageAppender());
			// 注册鼠标指针
			var mcd : * = new MouseCursorData();
			var data : Vector.<BitmapData>=new Vector.<BitmapData>();
			data.push(BitmapUtil.drawToBitmap(new CursorHVDrag()));
			mcd.data = data;
			Mouse.registerCursor("HVDrag", mcd);
			setInterval(autoSave, Time.MIN);
		}

		private function autoSave() : void {
			if (!detail.dirty) {
				return;
			}
			dispatch(new GUIEditorEvent(GUIEditorEvent.SAVE_UIXML, {isAutoSave:true}));
		}
	}
}
import kiwi.debug.ILogAppender;
import kiwi.util.sprintf;

import org.aswing.JOptionPane;

class ASWingMessageAppender implements ILogAppender {
	public function append(label : String, msg : String) : void {
		JOptionPane.showMessageDialog("警告", sprintf("%-20s", msg), null, null, true, null, JOptionPane.OK);
	}
}